package testJdk.anno.demo;

import org.junit.Test;

import java.lang.reflect.Method;

/**
 * @version 1.0.0
 * Created by cyd on 2024-07-29 16:48:10
 * @ClassName : testJdk.anno.demo.TestDemo
 * @Description : 类描述
 */
public class TestDemo {

    @Test
    public static void main(String[] args) throws Exception {
        Class<Person> cls = Person.class;
        Method[] methods = cls.getDeclaredMethods();
        for (Method method : methods) {
            method.setAccessible(true);
            if (method.isAnnotationPresent(MyTest.class)) {
                MyTest annotation = method.getAnnotation(MyTest.class);
                System.out.println(annotation);
                if ("yes".equals(annotation.exec())) {
                    method.invoke(cls.getConstructor().newInstance());
                }
            }
        }
    }
}
